package agent.client.android;

import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.logging.Logger;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CalendarView;

public class Da_A_2Activity extends Activity
{
	
	@SuppressWarnings("unused")
	private Logger logger = Logger.getLogger(this.getClass().getName());
	
	CalendarView calendarView;
	String dataTransferObject;
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		dataTransferObject = (String) getIntent().getExtras().get("dto");
		
	    setContentView(R.layout.da_a2);
	    
	    calendarView = (CalendarView)findViewById(R.id.calendarView2);
//	    calendarView.setMinDate(System.currentTimeMillis());
	    
	    
	    Button button = (Button)findViewById(R.id.a);
	    button.setOnClickListener(buttonListener);
	}
	

	private OnClickListener buttonListener=new OnClickListener() {
		
		public void onClick(View v) {
			
			long startTime=Long.valueOf(dataTransferObject.substring(0, dataTransferObject.length()-1));
			long endTime=calendarView.getDate();
			long currentTimeMillis=System.currentTimeMillis();
			
			if( endTime < startTime)
				endTime = startTime+86400000;
			
			GregorianCalendar gregorianCalendar = new GregorianCalendar();
			gregorianCalendar.setTimeInMillis(endTime);
			gregorianCalendar.setTimeZone(TimeZone.getDefault());
			
			dataTransferObject += gregorianCalendar.getTimeInMillis()+",";
			
			Intent intent = new Intent(Da_A_2Activity.this, SettingsActivity.class);
			intent.putExtra("dto", dataTransferObject);
			intent.putExtra("username", (String)getIntent().getExtras().get("username"));
			startActivity(intent);
			
			}
		
	};

}
